<?php 

use think\migration\Migrator;

class CreateStockTables extends Migrator
{
    public function change()
    {
        // 商品表
        $goods = $this->table('stock_goods', ['comment' => '商品库存表'])
            ->addColumn('name', 'string', ['limit' => 100, 'comment' => '商品名称'])
            ->addColumn('type', 'integer', ['comment' => '类型'])
            ->addColumn('total', 'integer', ['default' => 0, 'comment' => '总库存'])
            ->addColumn('used', 'integer', ['default' => 0, 'comment' => '已用库存'])
            ->addColumn('threshold', 'integer', ['comment' => '预警阈值'])
            ->addColumn('sort', 'integer', ['default' => 0, 'comment' => '排序'])
            ->addColumn('deleted', 'integer', ['default' => 0, 'comment' => '删除状态(0正常,1已删)'])
            ->addColumn('status', 'boolean', ['default' => 1, 'comment' => '状态(1启用 0禁用)'])
            ->addTimestamps()
            ->create();

        // 库存流水表
        $logs = $this->table('stock_logs', ['comment' => '库存流水表'])
            ->addColumn('goods_id', 'integer', ['comment' => '商品ID'])
            ->addColumn('type', 'integer', ['comment' => '类型(1入库 0出库)'])
            ->addColumn('num', 'integer', ['comment' => '数量'])
            ->addColumn('deleted', 'integer', ['default' => 0, 'comment' => '删除状态(0正常,1已删)'])
            ->addColumn('operator', 'string', ['limit' => 50, 'null' => true, 'comment' => '操作人'])
            ->addColumn('note', 'string', ['limit' => 255, 'null' => true, 'comment' => '备注'])
            ->addTimestamps()
            ->addIndex(['goods_id'])
            ->create();

        
    }
}